﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Model_Edit : BasePage
{
    private int id;
    protected void Page_Load(object sender, EventArgs e)
    {
        UserPower.CheckAction((int)FreeHouse.Power.Actions.TModel.Edit);
        int.TryParse(Request.QueryString["id"], out id);
        if (!IsPostBack)
            BindData();
    }
    protected void save_Click(object sender, EventArgs e)
    {
        error.Items.Clear();
        FreeHouse.Model.TModel model = new FreeHouse.Model.TModel();
        model.ModelName = ModelName.Text.Trim();
        model.Description = Server.HtmlEncode(Description.Value);
        model.ModelId = id;
        if (model.ModelName == "")
            error.Items.Add(new ListItem("填写:ModelName"));
        
        if (error.Items.Count == 0)
        {
            FreeHouse.BLL.TModel bll = new FreeHouse.BLL.TModel();
            bll.Update(model);
            error.Items.Add(new ListItem("编辑成功"));

        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default.aspx");
    }


    protected void BindData()
    {
        FreeHouse.Model.TModel model = new FreeHouse.BLL.TModel().GetModel(id);
        if (model == null) return;
        ModelName.Text = model.ModelName.Trim();
        Description.Value = model.Description.Trim();

    }
}
